function tableshua (){
    tableIn.reload("#ptable");
}
//文档加载完成后
$(function (){

    ajaxtable();

})

var tableIn = null;


function aa(res1,res2) {
    if(res1==0){
        return '<div style="line-height: 50px">'+'未审核' + '<br/>' + '<a className="layui-btn" onClick="auditprocess('+res2+');">'+'审核详情'+'</a>'+'</div>';
    }else if(res1==1){
        return '<div style="line-height: 50px">'+'审核中' + '<br/>' + '<a className="layui-btn" onClick="auditprocess('+res2+');">'+'审核详情'+'</a>'+'</div>';
    }else if(res1==2){
        return '<div style="line-height: 50px">'+'已审核' + '<br/>' + '<a className="layui-btn" onClick="auditprocess('+res2+');">'+'审核详情'+'</a>'+'</div>';
    }
}

//    表的渲染
function ajaxtable(){
    layui.use(['table','form'],function (){
        var table = layui.table,
            form = layui.form;


// 分页参数 1.页码 2.每页展示条数

        tableIn = table.render({
            elem:'#ptable',
            url:'/JsProduct/advanced/getAll',//数据接口
            height: 800,
            page:true,
            cols:[
                [
                    {field:"productId",title:'序号',hide:true},
                    {field:"productCode",title:'商品编号',width: 120,fixed:'left'},
                    {field: 'mainImage', title: '商品图片',templet:function(res){
                            return '<div><img src="'+res.mainImage+'" width="70px" height="70px"></a></div>';
                        }},
                    {field:"productName",title: "商品名称",width: 120},
                    {field:"currentpriceProduct",title: "商品价格",width: 120},
                    {field:"categroyId",title: "商品分类",width: 120},
                    {field:"categroyId",title: "上传人员",width: 120},
                    {field:"productLabel",title: "商品标签",width: 120},
                    {field: 'productSate',width: 100, title: '审核状态',templet:function(res){
                            if(res.productSate==0){
                                return '未审核';
                            }else{
                                return '已审核';
                            }
                        }},
                    {title:"操作",minWidth:200,toolbar:'#barDemo',align:"center"}

                ]
            ],

            parseData:function (res){//res 即为原始返回的数据
                return{
                    "state": res.state, //解析接口状态
                    "message": res.message, //解析提示文本0
                    "total": res.total, //解析数据长度
                    "data": res.data, //解析数据列表
                    "code":res.state,
                    "count":res.total,//解析数据长度
                };
            },
            toolbar:'#toolbarbtn'
        });

        table.on('tool(test)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;
            if(layEvent === 'detail'){ //查看
                layer.open({
                    type:2,
                    title:'查看商品',
                    content:"../../pages/product/productchakan.html",
                    area:['65%','100%'],
                    success:function (layero,index){
                        //表单数据回显，把表格当前行显示到子页面的表单内，find后括号内的是子页面表单的id
                        var body = layer.getChildFrame('body',index);
                        body.find("#productCode").val( obj.data.productCode);
                        body.find("#ylt").attr("src",obj.data.mainImage);
                        body.find("#productName").val(obj.data.productName);
                        body.find("#currentpriceProduct").val(obj.data.currentpriceProduct);
                        body.find("#categroyId").val(obj.data.categroyId);
                        body.find("#productLabel").val(obj.data.productLabel);
                        body.find("#productSate").val(obj.data.productSate);
                        body.find("#productId").val(obj.data.productId);
                        body.find("#createDate").val( obj.data.createDate);
                        body.find("#createUser").val(obj.data.createUser);
                        body.find("#searchKeywords").val(obj.data.searchKeywords);
                        body.find("#categroyId1").val(obj.data.categroyId);
                        body.find("#state").val(obj.data.state);
                        body.find("#xiaoliang").val(obj.data.xiaoliang);
                        body.find("#ensure").val(obj.data.ensure);
                        body.find("#fabulous").val(obj.data.fabulous);
                        body.find("#collectionVolume").val(obj.data.collectionVolume);
                        body.find("#hits").val(obj.data.hits);

                    }
                });
            } else if(layEvent === 'audit'){


                layer.open({
                    type: 2,
                    title: '审核',
                    content: "../../pages/product/shenheanniu.html",
                    area: ['80%', '80%'],
                    success: function (layero, index) {//弹出层成功弹出后的回调函数
                        // 父页面向子页面传参 -- iframe 层传数据
                        var body = layer.getChildFrame('body', index);//获取iframe页面
                        body.find('#pid').val(obj.data.productId);
                        body.find('#name').val(obj.data.productName);
                    }
                })
            }
        });


    })

}
